﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MacViet.DataBaseAPI;

public partial class Control_Appointment_Appointment : System.Web.UI.UserControl
{
    CLIENTSDataAPI cli = new CLIENTSDataAPI();
    APPOINTMENTSDataAPI app = new APPOINTMENTSDataAPI();
    public int acc_id;
    public string date;
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillGrid();
        }
    }

    protected void FillGrid()
    {
        DataTable dt = cli.getAll_APP(getSession_ACC_ID());
        grvTotalApp.DataSource = dt;
        grvTotalApp.DataBind();
    }

    protected int getSession_ACC_ID()
    {
        
        if (Session["acc_id"] != null)
            acc_id = int.Parse(Session["acc_id"].ToString());
        return acc_id;
    }
    
    protected void btnPaying_Click(object sender, EventArgs e)
    {
        string id = string.Empty;
        
        for (int i = 0; i < grvTotalApp.Rows.Count; i++)
        {

            GridViewRow rows = grvTotalApp.Rows[i];
            bool check = (rows.FindControl("chkStatus") as CheckBox).Checked;
            if (check)
            {
                if (id == string.Empty)
                {
                    id = grvTotalApp.DataKeys[i].Value.ToString();
                }
            }
        }

        Response.Redirect("~/Sale.aspx?APP_ID=" + id);
    }
   
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grvTotalApp.Rows.Count; i++)
        {
            string id = string.Empty;
            GridViewRow rows = grvTotalApp.Rows[i];
            bool check = (rows.FindControl("chkStatus") as CheckBox).Checked;
            if (check)
            {
                if (id == string.Empty)
                {
                    id = grvTotalApp.DataKeys[i].Value.ToString();
                    cli.status_WAIT_DENY(Int32.Parse(id));
                }
                else
                    id += grvTotalApp.DataKeys[i].Value.ToString() + ",";
            }
        }
        FillGrid();
    }

   
    protected void grvTotalApp_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.className='hightlighrow'");
            e.Row.Attributes.Add("onmouseout", "this.className='normalrow'");
        }
    }
    
}
